<template>
	<!-- 精酸量计算 -->
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350"
				:label-position="labelPosition" label="井筒半径(m)" prop="wellRadius">
				<u-input :border="border" placeholder="请输入井筒半径" v-model="model.wellRadius" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="有效厚度(m)" prop="effectiveThickness">
				<u-input :border="border" placeholder="请输入有效厚度" v-model="model.effectiveThickness" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="有效孔隙度" prop="porosity">
				<u-input :border="border" placeholder="请输入有效孔隙度" v-model="model.porosity" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="处理半径(m)" prop="treatmentRadius">
				<u-input :border="border" placeholder="请输入处理半径" v-model="model.treatmentRadius" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="酸液用量" prop="acidVolume">
					<span v-if="model.acidVolume"> {{model.acidVolume}} m³ </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">Q = π(R²-r²)hΦ</view>
				<view class="u-item-desc">式中：</view>
				<view class="u-item-desc">Q—酸液用量m³</view>
				<view class="u-item-desc">R—处理半径m</view>
				<view class="u-item-desc">r—井筒半径m</view>
				<view class="u-item-desc">h—有效厚度m</view>
				<view class="u-item-desc">Φ—有效孔隙度</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					wellRadius: '',
					effectiveThickness: '',
					porosity: '',
					treatmentRadius: '',
					acidVolume: ''
				},
				rules: {
					wellRadius: [{
						required: true,
						message: '请输入井筒半径',
						trigger: 'blur'
					}],
					effectiveThickness: [{
						required: true,
						message: '请输入有效厚度',
						trigger: 'blur'
					}],
					porosity: [{
						required: true,
						message: '请输入有效孔隙度',
						trigger: 'blur'
					}],
					treatmentRadius: [{
						required: true,
						message: '请输入处理半径',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						const r = parseFloat(this.model.wellRadius);
						const R = parseFloat(this.model.treatmentRadius);
						const h = parseFloat(this.model.effectiveThickness);
						const Φ = parseFloat(this.model.porosity);
						
						// Q = π(R²-r²)hΦ
						const Q = Math.PI * (Math.pow(R, 2) - Math.pow(r, 2)) * h * Φ;
						this.model.acidVolume = Q.toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>